﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using Elderos.Highlight.Search;
using Elderos.Utils;
using Elderos.Utils.Serialization;

namespace Elderos.Highlight
{
    [DataContract]
    public class ArticleHighlight
    {
        public ArticleHighlight()
        {}

        public ArticleHighlight(IEnumerable<Position> positions)
        {
            var winners = new List<HighlightItem>();

            var queue = new Queue<Position>(positions);
            while (queue.Count > 0)
            {
                var position = queue.Dequeue();
                if (position.Winner == null) continue;

                var winner = new HighlightItem {Position = position.CharInterval, WinnerID = position.Winner.EntityID};
                winners.Add(winner);
            }
        }

        [DataMember]
        public HighlightItem[] Winners { get; set; }

        [DataContract]
        public class HighlightItem
        {
            [DataMember]
            public Interval<int> Position { get; set; }
            [DataMember]
            public int WinnerID { get; set; }
        }
    }
}
